<?php

namespace App\Http\Controllers;

use App\Http\Requests\AlbumAddPost;
use App\Models\Album;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class AlbumController extends BaseController
{
    /**
     * 添加专辑
     *
     * @param AlbumAddPost $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function add(AlbumAddPost $request)
    {
        $album = new Album();
        $album->name = $request->get('name');
        $album->user_id = $this->userId;
        DB::beginTransaction();
        if ($album->save()) {
            if ($this->albumPP()) {
                DB::commit();
                return $this->jsonResultOk(['id' => $album->id]);
            }
        }

        DB::rollBack();
        return $this->jsonResultFail();
    }

    public function list(){
        $data = Album::query()->where(['user_id'=>$this->userId, 'status'=>2])->get();
        return $data;
    }
}
